{include file="common/head"/}
<style>
    .layui-checkbox-disbaled[lay-skin=primary] span {color: black;}
</style>
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>考核项</legend>
    </fieldset>
    <form class="layui-form layui-form-pane" lay-filter="form" id="form">

        <div  v-for="(item, index) in title_data">

            <div class="layui-form-item" v-if="item.type==1" >
                <div class="layui-input-4">
                    <span> {{index+1}}.</span><textarea style="padding-top: 10px;margin-top: -27px;padding-left: 10px;border: none;margin-left: 20px" readonly cols="200" rows="2" >{{item.title}}</textarea>
                </div>
            </div>
            <div class="layui-form-item" v-if="item.type==1" >
                <div class="layui-input-block" style="margin-left: 60px">
                     <span v-for="(item1, index1) in item.var_content">
                         <input :name="'timu'+item.title_id+'['+index1+']'" type="hidden" value="0">
                         <span v-if="item.answer" v-for="(item2, index2) in item.answer">

                              <input v-if="index2==index1 && item2==1" type="checkbox" lay-filter="ck" :id="'checkbox'+item.title_id+'['+index1+']'" :name="'timu'+item.title_id+'['+index1+']'" value="1" lay-skin="primary" :title="item1" checked >
                              <input v-if="index2==index1 && item2!=1" type="checkbox" lay-filter="ck" :id="'checkbox'+item.title_id+'['+index1+']'" :name="'timu'+item.title_id+'['+index1+']'" value="1" lay-skin="primary" :title="item1" >
                         </span>
                          <span v-if="item.answer==''">
                            <input  type="checkbox" lay-filter="ck" :id="'checkbox'+item.title_id+'['+index1+']'" :name="'timu'+item.title_id+'['+index1+']'" value="1" lay-skin="primary" :title="item1" >
                        </span>
                     </span>
                </div>
            </div>


            <div class="layui-form-item"  v-if="item.type==2">

                <div class="layui-input-4">
                    <span> {{index+1}}.</span><textarea style="padding-top: 10px;margin-top: -27px;padding-left: 10px;border: none;margin-left: 20px" cols="200" rows="2" >{{item.title}}</textarea>
                </div>
            </div>
            <div class="layui-form-item"  v-if="item.type==2">
                <div class="layui-input-block" style="margin-left: 60px">
                    <span v-for="(item4, key4,index4) in item.var_content">
                         <span v-if="item.answer" v-for="(item3, key3,index3) in item.answer">
                             <span v-if="key3==index4">
                                 {{item4}}:
                             </span>
                             <input v-if="key3==index4" type="text" class="test_value" :name="'timu'+item.title_id+'['+']'"  lay-skin="primary"  style="width: 30px;height: 20px;" :value="item3">
                             <span  style="margin-left: 30px;"></span>
                        </span>
                        <span v-if="item.answer==''">
                              {{item4}}:
                             <input type="text" class="test_value" :name="'timu'+item.title_id+'['+']'"  lay-skin="primary"  style="width: 30px;height: 20px;">
                            <span  style="margin-left: 30px;"></span>
                        </span>

                    </span>
                </div>
            </div>

        </div>

    </form>
<input type="hidden" id="teacher_id" value="{$teacher_id}">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="save(1)">保存</button>
            <button class="layui-btn" onclick="save(2)">提交</button>
            <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
        </div>
    </div>

</div>
{include file="common/foot"/}
<script type="text/javascript" src="/static/common/js/vue.js"></script>
<script>

    //数据初始化
    var app = new Vue({
        el: '#form',
        data: {
            //分类
            title_data: [],
            cate_id:'',
        },

    });
    layui.use(['form', 'layer'], function () {
        var form = layui.form, layer = layui.layer, $ = layui.jquery;
        form.render();

        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: "{:url('entry_teacher_show')}?teacher_id="+{$teacher_id}+"&cate_id="+{$cate_id},
            success : function(res) {
                app.title_data = res.list;
                setTimeout(function () {
                    form.render();
                },500);
                if((res.modify_remark!=null)&&(res.modify_remark!='')){
                    layer.open({
                        type: 1,
                        title:'修改项备注'
                        ,content: res.modify_remark //这里content是一个普通的String
                        ,area: ['500px', '300px']
                    });
                }

            },
        });


    });

    //通过
    function save(flag) {
        var test_value = $('.test_value');

        for (var i = 0; i < test_value.length; i++) {

            var key1 = $.trim(test_value.eq(i).val());
            if(key1==''){
                layer.msg('请完善填空题答案，其值不可为空',{icon:2});
                return;
            }

        }

        layer.prompt({
            formType: 2,
            value: '修改第XXX题,将XXX改为XXX',
            title: '修改项备注',
            area: ['800px', '350px'] //自定义文本域宽高
        }, function(value, index, elem){
            layer.close(index);
            $.ajax({
                type: 'POST',
                url: "{:url('title')}?teacher_id="+{$teacher_id}+"&cate_id="+{$cate_id}+"&flag="+flag+"&modify_remark="+value,
                data: $("#form").serialize(),
                success: function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1});
                        location.href = "{:url('entry_teacher')}?teacher_id="+{$teacher_id};
                    }else{
                        layer.msg(res.msg,{icon:2});
                    }

                },
                dataType: 'json'
            });
        });

    }


</script>